create or replace view vac_application_4_1 as
with aa as
 (select
   aa.application_id,
   aa.workspace,
   aa.application_name,
   aa.ALIAS,
   aa.HOME_LINK,
   page_template,
   error_page_template,
   logging,
   application_primary_language,
   language_derived_from,
   date_format,
   timestamp_format,
   timestamp_tz_format,
   auto_time_zone,
   default_error_display_location,
   image_prefix,
   authentication_scheme_type,
   login_url,
   logout_url,
   logo_type,
   logo,
   logo_attributes,
   public_user,
   proxy_server,
   media_type,
   authentication_scheme,
   version,
   availability_status,
   unavailable_text,
   restrict_to_user,
   debugging,
   exact_substitutions,
   build_status,
   publish,
   vpd,
   authorization_scheme,
   authorization_scheme_id,
   last_updated_by,
   to_char(last_updated_on, 'YYYY-mm-dd') last_updated_on,
   to_char(theme_number) theme_number,
   global_notification,
   session_state_protection,
   to_char(maximum_session_life_seconds) maximum_session_life_seconds,
   session_lifetime_exceeded_url
   from apex_applications aa
  --where aa.application_id = nv('P100_APP1_ID')
  )
select APPLICATION_ID,
       authorization_scheme_id,
       last_updated_by,
       last_updated_on,
       U_NAME,
       U_VALUE,
       'APEX_APPLICATIONS' src_view_name
  from aa UNPIVOT INCLUDE NULLS(u_value FOR u_name IN(workspace,
                                                      application_name,
                                                      ALIAS,
                                                      HOME_LINK,
                                                      page_template,
                                                      error_page_template,
                                                      logging,
                                                      application_primary_language,
                                                      language_derived_from,
                                                      date_format,
                                                      timestamp_format,
                                                      timestamp_tz_format,
                                                      auto_time_zone,
                                                      default_error_display_location,
                                                      image_prefix,
                                                      authentication_scheme_type,
                                                      login_url,
                                                      logout_url,
                                                      logo_type,
                                                      logo,
                                                      logo_attributes,
                                                      public_user,
                                                      proxy_server,
                                                      media_type,
                                                      authentication_scheme,
                                                      version,
                                                      availability_status,
                                                      unavailable_text,
                                                      restrict_to_user,
                                                      debugging,
                                                      exact_substitutions,
                                                      build_status,
                                                      publish,
                                                      vpd,
                                                      authorization_scheme,
                                                      theme_number,
                                                      global_notification,
                                                      session_state_protection,
                                                      maximum_session_life_seconds,
                                                      session_lifetime_exceeded_url));

